package com.un.ebs.invoice.listener;

import com.un.ebs.inventory.enums.InventoryTypeEnum;
import com.un.ebs.invoice.mapper.InvoiceNoteMapper;
import com.un.ebs.invoice.service.InvoiceNoteService;
import com.un.ebs.workflow.event.WorkflowInstancePushEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@Async
public class InvoiceWorkflowInstancePushListener implements ApplicationListener<WorkflowInstancePushEvent> {

    //private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private InvoiceNoteService invoiceNoteService;

    @Override
    public void onApplicationEvent(WorkflowInstancePushEvent event) {
        if (!event.isClose()) {
            return;
        }
        if (!event.isPass()) {
            return;
        }
        if (event.getInventoryTypeEnum() != InventoryTypeEnum.INVOICE_SALE) {
            return;
        }

        invoiceNoteService.workflowPass(event.getNoteId(), event.getWorkflowInstanceId());
    }
}
